/** 判断任意给定的数值是否是质数*/
let num = 5;

if (num == 0 || num == 1) {
    console.log(num + "既非质数也非合数");
} else {
    let count = 0;
    for (let i = num; i > 0; i--) {
        if (num % i == 0) {
            count++;
        }
    }
    if (count == 2) {
        console.log(num + "是质数");

    } else {
        console.log(num + "是合数");
    }
}
/** ********************************** */
/** 将 1 到 100 之间的质数输出到控制台
 * 将 1 到 100 之间的质数个数输出到控制台
 */
let count = 0;
let count_sum = 0;
let x = '';
console.log("1 到 100 之间的质数:");
for (let i = 1; i <= 100; i++) {
    for (let j = 1; j <= i; j++) {
        if (i % j == 0) {
            count++;
        }
    }
    if (count == 2) {
        x = x + i + ' ';
        // process.stdout.write(i + ' '); //输出不换行
        count_sum = count_sum + 1;
    }
    count = 0;

}
console.log(x);
console.log('\n' + "1 到 100 之间的质数个数:" + count_sum);
console.log('\n');
/********************************************************** */
/**从质数2开始统计，列出100个质数，每行输出10个，分10行输出 */
let total = 0;
let count_1 = 0;
let n = 2;
let s = '';
while (total < 100) {
    for (let i = 1; i <= n; i++) {
        if (n % i == 0) {
            count_1++;
        }
    }
    if (count_1 == 2) {

        // process.stdout.write(n + '\t');//输出不换行
        total = total + 1;
        s = s + n + (total % 10 == 0 ? '' : '\t');
        if (total % 10 == 0) {
            console.log(s);
            // console.log('\n');
            s = '';
        }
    }
    count_1 = 0;
    n = n + 1;
}
if (s) { console.log(s); }